package com.aaa.controller;

import com.aaa.entity.TPlan;
import com.aaa.result.Result;
import com.aaa.service.TPlanService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.api.ApiController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 计划标准表(TPlan)表控制层
 *
 * @author makejava
 * @since 2025-05-07 15:18:30
 */
@RestController
@RequestMapping("/core/tPlan")
public class TPlanController extends ApiController {

    /**
     * 服务对象
     */
    @Resource
    private TPlanService tPlanService;

    /**
     * @return 所有数据
     */
    @PostMapping("/getPageList")
    public Result<Object> getPageList(@RequestBody Map<String,Object> param) {
        Object planName = param.get("planName");
        List<TPlan> list = tPlanService.list(Wrappers.lambdaQuery(TPlan.class).eq(Objects.nonNull(planName), TPlan::getPlanName, planName));
        return Result.OK(list);
    }

    /**
     * 新增数据
     * @param tPlan 实体对象
     * @return 新增结果
     */
    @PostMapping("/saveEntity")
    public Result<String> saveEntity(@RequestBody TPlan tPlan) {
        boolean save = this.tPlanService.save(tPlan);
        return Result.OK("新增成功");
    }

    /**
     * 修改数据
     *
     * @param tPlan 实体对象
     * @return 修改结果
     */
    @PutMapping("/updateEntity")
    public Result<String> updateEntity(@RequestBody TPlan tPlan) {
        this.tPlanService.updateById(tPlan);
        return Result.OK("修改成功");
    }

    /**
     * 删除数据
     * @return 删除结果
     */
    @DeleteMapping("/deleteEntity/{id}")
    public Result<String>  deleteEntity(@PathVariable("id") Long id) {
        boolean b = this.tPlanService.removeById(id);
        return Result.OK("删除成功");
    }
}

